home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / C / ESPRESSO.ZIP / ESSEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-14  |  2.1 KB  |  78 lines

  1. /*
  2.     module: essen.c
  3.     purpose: Find essential primes in a multiple-valued function
  4. */
  5.  
  6. #include "espresso.h"
  7.  
  8. /*
  9.     essential -- return a cover consisting of the cubes of F which are
  10.     essential prime implicants (with respect to F u D); Further, remove
  11.     these cubes from the ON-set F, and add them to the OFF-set D.
  12.  
  13.     Sometimes EXPAND can determine that a cube is not an essential prime.
  14.     If so, it will set the "NONESSEN" flag in the cube.  Also, IRREDUNDANT
  15.     will mark all cubes in the relatively essential set as "RELESSEN".
  16.     Note that all essential prime implicants must be relatively essential.
  17. */
  18.  
  19. pcover essential(Fp, Dp)
  20. IN pcover *Fp, *Dp;
  21. {
  22.     register pcube last, p;
  23.     pcover E, F = *Fp, D = *Dp;
  24.  
  25.     /* set all cubes in F active */
  26.     sf_active(F);
  27.  
  28.     /* Loop for all cubes of F */
  29.     E = new_cover(10);
  30.     foreach_set(F, last, p)
  31.         /* Only need to check relative essentials which aren't already known
  32.         to be nonessential primes */
  33.         if (TESTP(p, RELESSEN) && ! TESTP(p, NONESSEN))
  34.             if (essen_cube(F, D, p)) {
  35.                 if (debug & ESSEN)
  36.                     printf("ESSENTIAL: %s\n", pc1(p));
  37.                 E = sf_addset(E, p);
  38.                 RESET(p, ACTIVE);
  39.                 F->active_count--;
  40.             }
  41.  
  42.     *Fp = sf_inactive(F);               /* delete the inactive cubes from F */
  43.     *Dp = sf_append(D, sf_save(E));     /* add the inactive cubes to D */
  44.     return E;
  45. }
  46.  
  47.  
  48.  
  49. /*
  50.     essen_cube -- check if a single cube is essential or not
  51. */
  52. bool essen_cube(F, D, c)
  53. IN pcover F, D;
  54. IN pcube c;
  55. {
  56.     register pcube p, last, pr, *R1;
  57.     register pcover R;
  58.     bool essen;
  59.  
  60.     /* Form R = consensus of c with each cube of F and D */
  61.     R = new_cover(F->count + D->count);
  62.     pr = R->data;
  63.  
  64.     foreach_set(F, last, p)
  65.         if (p != c && consensus(pr, p, c))
  66.             pr += R->wsize, R->count++;
  67.     foreach_set(D, last, p)
  68.         if (consensus(pr, p, c))
  69.             pr += R->wsize, R->count++;
  70.  
  71.     R1 = cube1list(R);
  72.     essen = ! cube_is_covered(R1, c);
  73.     free_cubelist(R1);
  74.  
  75.     free_cover(R);
  76.     return essen;
  77. }
  78.